<div class="form-container">
	<form id="form">
		<table class="tableform">
			<tr>
				<th style="width:70px;">所属公司：</th>
				<td colspan="4">
					<input id="company" name="companyId" class="easyui-validatebox" type="text" style="width: 230px; height:25px;" />
				 	<a onClick="$company.combotree('setValue', '');$category.combobox('setValue', 'catalog');" class="easyui-linkbutton ml-3" data-options="plain: true"><i class='fa fa-remove fa-120 pt-5 pb-4 icon-red'></i></a>
				 	<a onClick="$company.combotree('reload')" class="easyui-linkbutton ml-3" data-options="plain: true"><i class='fa fa-refresh fa-120 pt-5 pb-4 icon-green'></i></a>
				</td>
			</tr>
			<tr>
				<th style="width:70px;">角色名称：</th>
				<td>
					<input name="fullName" class="easyui-validatebox" type="text" data-options="required: true" style="width:222px;"/>
				</td>
			</tr>
			<tr>
				<th>角色代码：</th>
				<td>
					<input name="code" class="easyui-validatebox" type="text" data-options="required: true" style="width:222px;"/>
				</td>
			</tr>
			<tr>
				<th>角色分类：</th>
				<td>
					<input id="category" name="category" data-options="required: true" style="width:230px;height:25px;">
				</td>
			</tr>
			<tr>
				<th>排序：</th>
				<td>
					<input name="sortCode" class="easyui-numberbox" type="text" data-options="prompt: '不填写则为默认排序'" style="width:228px;" />
				</td>
			</tr>
			<tr>
				<th>备注：</th>
				<td colspan="4">
					<textarea name="remark" style="width:223px;height:50px;"></textarea>
				</td>
			</tr>
			<tr style="display:none">
				<td>
					<input type="hidden" name="id" value="${id!}">
				</td>
			</tr>
		</table>
	</form>
</div>

<script>
	var form_url = "${ctx}/manager/base/role/add", id = "${id!}" ;
	$(function(){
		$('#icheck input').iCheck({
			checkboxClass: 'icheckbox_minimal-blue',
			radioClass: 'iradio_square-blue'
	   	});
	   	
		$company = $("#company").combotree({
			url: "${ctx}/manager/base/company/treegrid",  method: "GET",
			idFiled:'companyId', editable: false, required:true, lines:true, autoShowPanel: false
		});
		$("#category").combobox({
			textField: 'value', valueField: 'label',
			data: [{ label: '系统角色', value: '系统角色' },{ label: '业务角色', value: '业务角色' }],
			panelHeight:'auto', editable:false, autoShowPanel: true
		}) ;
		
		if(undefined != id && "" != id) {
			form_url = "${ctx}/manager/base/role/update" ;
			$.ajax({
				type: "GET", dataType: "JSON",
				url: "${ctx}/manager/base/role/get/"+id,
				success: function(result) {
					$("input[name=locked][value="+result.locked+"]").iCheck('check') ;
					$("#form").form("load", result);
				},
				complete: function(XMLHttpRequest, textStatus){},
				error: function(XMLHttpRequest, textStatus, errorThrown){
					$.easyui.loaded();
					if(XMLHttpRequest.status == 403) {
						$.messager.alert(XMLHttpRequest.statusText, XMLHttpRequest.responseText, "warning");
					} else {
						$.messager.alert("错误", "发生未知错误", "error");
					}
				}
			});
		}
		
	});
	
	//提交表单数据
	var submitNow = function($d, $dg, flag) {
		$.post(form_url, $("#form").form("getData"), function(result) {
			if (result.status) {
				$dg.datagrid('reload');alertify.success(result.message);$.easyui.loaded();
				if(flag==undefined||flag==false){$d.dialog("close") ;}
			} else {
				$.easyui.loaded();$.messager.alert("错误", result.message, "error");
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	};
	
	//验证表单
	var submitForm = function($d, $dg, flag) { 
		if($('#form').form('validate')) {
			$.easyui.loading({ msg: "数据提交中，请稍等..." });
			submitNow($d, $dg, flag) ;
		}
	};
</script>

